package com.example.fastmybatis.controller;

import com.example.fastmybatis.service.TUserService;
import com.example.fastmybatis.util.CreateDataUtil;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @Description:以原始mybatis方式CRUD操作数据库，测试fastmybatis框架是否兼容mybatis
* @Author:Mujiutian
* @CreateDate:2019/6/8 12:09
* @UpdateUser:
*/
@RestController
@RequestMapping(value = "/user/mybatis")
public class User2Controller {

   @Autowired
   @Qualifier("userService2")
   TUserService userService;

   @PostMapping(value = "/addUser")
   public String addUser(){
       userService.addUser(CreateDataUtil.getUser());
       return "fastmybatis框架使用mybatis方式："+"创建数据成功";
   }
   @Delete(value = "/deleteUser")
   public String deleteUser(int id){
       userService.deleteUser(id);
       return "fastmybatis框架使用mybatis方式："+"删除数据成功";
   }

   @PostMapping(value = "/updateUser")
   public String updateUser(int id){
       userService.updateUser(CreateDataUtil.getuserForMap(id));
       return "fastmybatis框架使用mybatis方式："+"更新数据成功";
   }

   @GetMapping(value = "/getUser")
   public String getUser(int id){
       userService.getUser(id);
       return "fastmybatis框架使用mybatis方式："+"获取数据成功";
   }

   @GetMapping(value = "/getPageUsers")
   public String getPageUsers(){
       return "mybatis的分页查询自己写吧：";
   }

    /**
     * @description:更详细更简单的获取分页用户数据
     * @author:MuJiuTian
     * @createDate: 2019/6/8 15:29
     */
    @GetMapping(value = "/getEasyPageUsers")
    public String getEasyPageUsers(int pageIndex,int pageSize){
        return "mybatis的分页查询自己写吧";
    }

    /**
     * @description:以id排序获取用户
     * @author:MuJiuTian
     * @createDate: 2019/6/8 17:27
     */
    @GetMapping(value = "/getUsersForOrder")
    public String getUsersForOrder(){
        return userService.getUsersForOrder().toString();
    }

}
